From f8a303b0e53293f8f077a8bdf72b1d9389761b5d Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 2 Aug 2020 13:09:00 -0400 Subject: [PATCH] popovermenu: Avoid a critical While we guarantee that the widget that a controller is attached to stays around while it is handling an event, the same is not true for the root that the widget belongs to. In corner cases (such as clicking "Close" in the fallback window menu), it may already be gone. Avoid a critical in that case. Fixes: #2998 --- gtk/gtkpopovermenu.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/gtk/gtkpopovermenu.c b/gtk/gtkpopovermenu.c index 2108f15535..707429c730 100644 --- a/gtk/gtkpopovermenu.c +++ b/gtk/gtkpopovermenu.c @@ -228,7 +228,14 @@ static void focus_out (GtkEventController *controller, GtkPopoverMenu *menu) { - GtkWidget *new_focus = gtk_root_get_focus (gtk_widget_get_root (GTK_WIDGET (menu))); + GtkRoot *root; + GtkWidget *new_focus; + + root = gtk_widget_get_root (GTK_WIDGET (menu)); + if (!root) + return; + + new_focus = gtk_root_get_focus (root); if (!gtk_event_controller_focus_contains_focus (GTK_EVENT_CONTROLLER_FOCUS (controller)) && new_focus != NULL) -- 2.30.2